// 字符串的Iterator接口
{
  const sth = 'hi'
  const ite = sth[Symbol.iterator]()
  console.log(ite.next()) // { value: 'h', done: false }
  console.log(ite.next()) // { value: 'i', done: false }
  console.log(ite.next()) // { value: undefined, done: true }
  console.log([...sth]) // [ 'h', 'i' ]
}
// 数组
{
  const arr = ['red', 'green', 'blue']
  for (let x of arr) {
    console.log(x) // red  green  blue
  }
  arr.foo = 'hello'
  for (let x of arr) {
    console.log(x) // red  green  blue
  }
  for (let y in arr) {
    console.log(y) // 0 1 2 foo
  }
}
// Set 和 Map
{
  const eng = new Set(['Geoko', 'Trident', 'WebKit', 'WebKit'])
  for (let x of eng) {
    console.log(x)
  }
  // Geoko
  // Trident
  // WebKit

  const es6 = new Map()
  es6.set('edition', 6)
  es6.set(1000, 'TC39')
  es6.set(true, 'ECMA-262')
  for (let x of es6) {
    const [key, value] = x
    console.log(`key: ${key}, value: ${value}`)
  }
  // key: edition, value: 6
  // key: 1000, value: TC39
  // key: true, value: ECMA-262
}


// 类似数组对象
{
  let str = 'hello'
  for (let x of str) {
    console.log(x) // h  e  l  l  o
  }
  // arguments对象
  function print () {
    for (let x of arguments) {
      console.log(x) // a  b  c
    }
  }
  print('a', 'b', 'c')
}

// 与其他遍历语法比较
{
  for (let x of [1, 2, 3, 4, 5, 6, 7]) {
    if (x > 4) {
      break
    }
    console.log(x) // 1 2 3 4
  }
}